package com.qf.controller;

import com.qf.pojo.Car;
import com.qf.pojo.Order;
import com.qf.pojo.ResponseData;
import com.qf.service.OrderService;
import com.qf.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderSys {
    @Autowired
   private OrderService orderService;
@RequestMapping("/add")
    public ResponseData add(Order order){
    //    //补全信息
    order.setStatus("已预约");
    //调用业务层
    Boolean flag= orderService.addOrder(order);
//    System.out.println(oprice);
    if (!flag){
        return JsonUtils.createJson(0,"提交失败");
    }
    return JsonUtils.createJson(1,flag);
}

@RequestMapping("all")
    public ResponseData all(Integer page){
    //调用实体类
    Map<String,Object>  map = orderService.findAll(page,5);
    if (map==null){
        return JsonUtils.createJson(0,"查询失败");
    }
    return JsonUtils.createJson(1,map);
}

@RequestMapping("/delete")
    public ResponseData delete(Integer oid){
        Boolean flag = orderService.deleteOrder(oid);
            System.out.println(oid);
        if (!flag){
            return JsonUtils.createJson(0,"无法删除");
        }
        return JsonUtils.createJson(1,flag);
    }



}
